//
//  LaunchViewController.m
//  ebook
//
//  Created by 吴超飞 on 2017/3/6.
//  Copyright © 2017年 Moton. All rights reserved.
//

#import "LaunchViewController.h"
#import "GuestLoginManager.h"
#import "DownloadManager.h"
#import "MTTabBarController.h"
#import "AdViewManager.h"

@interface LaunchViewController ()

@end

@implementation LaunchViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self requestStoreMenuData:^{
        
        [self goToTabbarController];
    }];
}

- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)requestStoreMenuData:(void(^)(void))complete {
    
    [GuestLoginManager autoLogin:^(BOOL issuc) {
        MTLog(@"自动登录%@!", issuc?@"成功":@"失败");
        if(issuc){
            [[NSUserDefaults standardUserDefaults] setFloat:[[NSDate date]timeIntervalSince1970] forKey:kLoginTime];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
        [EbookNetRequest getStoreMenuSuccess:^(int stateCode, NSString *successMsg, NSDictionary *dict) {
            [[NSUserDefaults standardUserDefaults] setObject:[NSKeyedArchiver archivedDataWithRootObject:dict] forKey:KBookCityData];
            [[NSUserDefaults standardUserDefaults] synchronize];
            [[DownloadManager shareInstance] restoreDownload];
            if(complete)complete();
        } failed:^(int stateCode, NSString *failMsg) {
            if(complete)complete();
        }];
    }];
}

-(void)goToTabbarController{
    
    MTTabBarController *tabBar = [[MTTabBarController alloc] init];
    [self.navigationController pushViewController:tabBar animated:NO];
    MTLog(@"跳转到MTTabBarController");
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
